package xy.come.juhenews.Activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.transition.Explode;
import android.transition.Slide;
import android.util.Log;
import android.view.Window;

import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import butterknife.BindView;
import butterknife.ButterKnife;
import xy.come.juhenews.Base.BaseActivity;
import xy.come.juhenews.R;

/**
 * Created by Xia_焱 on 2018/7/19.
 * e-mail：XiahaotianV@163.com
 * 新闻详情页
 */

public class    NewsDetailsActivity extends BaseActivity {
    @BindView(R.id.web_x5)
    WebView webX5;
    private String mUrl;
    @Override
    public int getLayoutId() {
        return R.layout.activity_news_details;
    }

    @SuppressLint("NewApi")
    @Override
    protected void initView() {
        getWindow().setExitTransition(new Explode());
        getWindow().setEnterTransition(new Explode());
        mUrl = getIntent().getStringExtra("url");
        webX5.setWebViewClient(client);
        loadWebUrl();
    }


    @Override
    protected void initData() {

    }

    private void loadWebUrl() {
        if (null != mUrl && mUrl.length() > 0) {
            webX5.loadUrl(mUrl);
        }
    }

    private WebViewClient client = new WebViewClient() {
        /**
         * 防止加载网页时调起系统浏览器
         */
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        public void onReceivedHttpAuthRequest(WebView webview,
                                              com.tencent.smtt.export.external.interfaces.HttpAuthHandler httpAuthHandlerhost, String host,
                                              String realm) {

        }

        @Override
        public void onPageFinished(WebView webView, String s) {
            super.onPageFinished(webView, s);

        }

        @Override
        public void onReceivedError(WebView webView, int i, String s, String s1) {
            System.out.println("***********onReceivedError ************");
            super.onReceivedError(webView, i, s, s1);
        }

        @Override
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            System.out.println("***********onReceivedHttpError ************");
            super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
        }
    };
}
